#include "popupmanager.h"
#include "source/logger.h"

void PopupManager::showPopup(const QString& title, const QString& message) {
    title_ = title;
    message_ = message;
    emit titleChanged();
    emit messageChanged();
    popupQueue_.enqueue(qMakePair(title, message));
    if (!showingPopup_) {
        showingPopup_ = true;
        emit showPopupSignal();
    }
}

void PopupManager::hidePopup() {
     if (popupQueue_.isEmpty()) {
        // 如果队列为空，直接返回或进行其他处理
        LogError << "PopupManager::hidePopup is empty";
        return;
    }
    auto popup = popupQueue_.dequeue();
    title_ = popup.first;
    message_ = popup.second;
    emit titleChanged();
    emit messageChanged();
    if (popupQueue_.isEmpty())
    {
        showingPopup_ = false;
        emit hidePopupSignal();
    }
}

void PopupManager::hideAllPopups() {
    if (!popupQueue_.isEmpty()) {
        popupQueue_.clear();
    }
    showingPopup_ = false;
    emit hidePopupSignal();
}
